July 12, 1994 GETKEY ver. 2.0 by Matthew G. Moody 206 Waterwood Dr. Goose Creek, SC 29445 (803) 572-4868 CIS 72607,3461 This is my eighth update to GETKEY. The first version simply retrieved a key from the keyboard and returned a value to DOS that ERRORLEVEL could detect. My brother asked if MSDOS 6 already had a batch file command that would do this already. So I looked into it and sure enough, there was. That command is CHOICE. So I set about writing a program to mimic it, mainly for the challenge. The second version of GETKEY followed CHOICE exactly, with the exception of the time delay parameter. The third version included that parameter. The fourth revision accepted menu items and set the display colors for the menu. The fifth revision takes the tilde prefixed characters in the menu items and forces them to be the valid keys to accept, in other words, the /c switch is ignored when the program encounters a tilde character (~) within an /m switch. Also, I changed the key prompt to output in highlight. To make this more like DOS's CHOICE when you press a valid key it is displayed at the end of the prompt string. The sixth was a minor revision to solve the bug that occurred when using the timed response switch. It was displaying "null pointer assignment" after the program ended. That was a tricky little bugger to find. Thanks to Glenn R. Sogge for his help in locating that sneaky rascal. The seventh revision brings the capability to read in a text file with the command switches listed in it so the user may create longer menus. This revision opens a window upon a screen background and displays the prompt and menu items listed either on the command-line or from the .GKS file. The menu items are automatically formatted into columns and rows. This will give you a total of 93 possible menu items (in 50-line mode). Previous version .GKS files or batch files using the /m parameter with the format /m1,12"menuitem ~1" are no longer valid. When the program ends, the original screen is restored. This revision also solves a bug with extended keys (F1-F10) and extended key combinations (Ctrl-F1,Alt-F1,Shift-F1, etc.) causing a false valid selection. This version is also the first time I am asking for donations. If you find the program useful please send me $10 at the above address and I will add you to my list of registered users and send you a copy of the most recent version along with other utilities, that have not been bouncing all over the BBS's and the next update when it is available. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ DISCLAIMER ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» º This file is not intended to teach the user the batch programming language.º º It is only intended to demonstrate how GETKEY is used in batch files. More º º information on batch file programming can be found in your DOS manual, and º º several informative books on the subject, such as "MS-DOS Batch File º º Programming" by Ronny Richardson and "Advanced MS-DOS Batch File Programming"º º by Dan Gookin both published by TAB Books, as well as many other books and º º magazines. º º º º The author makes no warranty of any kind, express or implied, including º º without limitation, any warranties of merchantability and/or fitness for a º º particular purpose. º º The author shall not be held liable for any damages, whether direct, º º indirect, special or consequential arising from a failure of this program to º º operate in the manner desired by the user. The author shall not be held º º liable for any damage to data or property which may be caused directly or º º indirectly by the use of this program. º º In no event will the author be held liable for any damages, including (but º º not limited to) any lost profits, lost savings or other incidental or º º consequential damages arising out of the use or inablity to use this program,º º or for any claim by any other party. º ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ List of files included with GETKEY20.ZIP: -- Batch files demonstrating GetKey -- COLORS1.BAT - demonstrate using menuitem in batch file COLORS2.BAT - demonstrate using menuitem in batch file COLORS3.BAT - demonstrate using menuitem in batch file COLORS4.BAT - demonstrate using .GKS file in batch file FILEMENU.BAT - demonstrate using case sensitivity FMT.BAT - format floppy disks using menu, checks for files first CREATMEN.BAT - creates a .GKS file one item at a time and displays the menu RUNME.BAT - run demo batch files listed here TEST.BAT - demonstrate using multiple option keys on menu items TEST2.BAT - demonstrate using multiple option keys on menu items and blinking colors YESNO.BAT - simple demonstration D.BAT - demonstrate setting dir options SCREEN.BAT - demonstrate setting ANSI screen colors SAMPLE.BAT - demonstrate GETKEY options MENU5.BAT - demonstrate 50-line mode and 93 menu items M25.COM - Mode25 switch to 25-line screen M50.COM - Mode50 switch to 43/50-line screen (Requires EGA/VGA) GK.EXE - GetKey version 2.0 GE.EXE - GetEnterKey version 1.0 -- GKS and SCR files used by the above listed batch files -- COLORS.GKS - used by COLORS4.BAT MENU.GKS - used by FILEMENU.BAT RUNME.GKS - used by RUNME.BAT SCREEN.GKS - used by SCREEN.BAT MENU1.GKS - used by COLORS4.BAT DIRSORT.GKS - used by D.BAT MENU5.GKS - used by MENU5.BAT CREATMEN.GKS - used, created and destroyed by CREATMEN.BAT ENTERN.SCR - used by FMT.BAT FILELIST.LST - List of included files GETKEY.TXT - History of GetKey and instruction for use GETKEY waits for the user to choose one of a set of choices. The syntax for GETKEY is: GK [{/|-}C[:]choices] [{/|-}N] [{/|-}S] [{/|-}T[:]c,nn] [{/|-}D[:]b,f,h] ["text"] [{/|-}M"~menu 1"] ... [{/|-}M"menu ~n] [{/|-}Fmenufile.gks] [{-|/}{h|H|?}] NOTE: You may use - or / to delimit parameters. /C[:]choices Specifies allowable keys. Default is YN /N Do not display choices and ? at end of prompt string. /S Treat choice keys as case sensitive. /T[:]c,nn Default choice to c after nn seconds /D[:]b,f,h Display attributes for background, foreground, and highlight. /M"menu ~1" Text string to display as a menu item. /Fmenufile.gks Menu file with arguments (It is assumed the file has the .gks extension. You may use the full pathname i.e. -fc:\dos\menufile) "text" Prompt string to display /? Display help ERRORLEVEL is set to offset of key user presses in choices. If you type GK /? at the command line you will get the help screen displayed below: GETKEY ver 2.0 °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ GETKEY Help Screen ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»°° °º Syntax: º±± °º GK [{/|-}C[:]keys] [{/|-}N] [{/|-}S] [{/|-}T[:]c,nn] º±± °º [{/|-}D[:]b,f,h] [{/|-}M"menu ~1"] ["text"] [{/|-}Ffilename.gks] º±± °º º±± °º /C[:]keys Specifies allowable keys. Default is YN º±± °º /N Do not display choices and ? at end of prompt string. º±± °º /S Treat choice keys as case sensitive. º±± °º /T[:]c,nn Default choice to c after nn seconds. º±± °º /D[:]b,f,h Display attributes for background, foreground, and º±± °º highlight. Default is 0,7,15 (black,light gray,white). º±± °º /M"~menu text" Text string to display as a menu item. º±± °º (NOTE: '~' marks allowable keys.) º±± °º /Ffilename.gks GETKEY binary file with valid parameter lists. º±± °º "text" Prompt string to display. º±± °º /{?|H} Displays this help screen. º±± °º º±± °º Press ÄÙ to continue ... º±± °ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± °°°±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° If you type GK at the command line you will get this: (Actual screen shot) GK EXE 95,259 07-09-94 1:59a GE EXE 31,095 07-09-94 1:59a GETKEY EXE 95,027 07-09-94 1:59a COLORS GKS 432 07-09-94 1:59a MENU GKS 534 07-09-94 1:59a MENU2 GKS 125 07-09-94 1:59a TEST1 GKS 256 07-09-94 1:59a SCREEN GKS 133 07-09-94 1:59a D ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» MEº º±± DIº [Y,N]? º±± MEº º±± MEº º±± MEº º±± FIº º±± GEÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± ENTE±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± WPLABEL SCR 11 07-09-94 1:59a DBLABEL SCR 14 07-09-94 1:59a GETKEY TXT 14,388 07-09-94 3:27p 42 file(s) 325,958 bytes 55,623,680 bytes free C:\DOS\BATCH\1>gk (this is the command sent to GETKEY) Notice GETKEY created a window and 'Y' and 'N' are highlighted. This is the default when you use no switches and no prompt. Now let's try sending a prompt to GETKEY with this command: C:>GK "Your choice" (Actual screen shot) MENU GKS 534 07-09-94 1:59a MENU2 GKS 125 07-09-94 1:59a TEST1 GKS 256 07-09-94 1:59a SCREEN GKS 133 07-09-94 1:59a D GKS 274 07-09-94 1:59a MENU1 GKS 535 07-09-94 1:59a DIRSORT GKS 276 07-09-94 1:59a MENU3 GKS 675 07-09-94 1:59a MEÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ Your choice ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» MEº º±± FIº Your choice [Y,N]? º±± GEº º±± ENº º±± WPº º±± DBº º±± GEÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± 55,623,680 bytes free C:\DOS\BATCH\1>gk C:\DOS\BATCH\1>edit getkey.txt C:\DOS\BATCH\1>gk "Your choice" (this is the command sent to GETKEY) Now GETKEY displays the prompt followed by the valid key choices. Notice also, that the prompt is used to label the window. In the previous example there was no prompt and no label on the window. Suppose you don't want to display the valid keys, in that case the /n switch will suppress the display of the valid keys as in the following screen shot: (Actual screen shot) D GKS 274 07-09-94 1:59a MENU1 GKS 535 07-09-94 1:59a DIRSORT GKS 276 07-09-94 1:59a MENU3 GKS 675 07-09-94 1:59a MENU4 GKS 660 07-09-94 1:59a MENU5 GKS 1,725 07-09-94 1:59a FILELIST LST 445 07-09-94 3:29p GETKEY MAR 22,201 07-09-94 1:59a ENÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ Your choice ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» WPº º±± DBº Your choice º±± GEº º±± º º±± º º±± º º±± C:ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± C:\DOS\BATCH\1>edit getkey.txt C:\DOS\BATCH\1>gk "Your choice" C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk "Your choice" /n (this is the command sent to GETKEY) GETKEY goes beyond merely replacing CHOICE. With it, you aren't limited just to posing yes/no questions. For example, using GETKEY, you could have your batch file pose this question to the user: C:>GK "Select setup: Command line, DOS Shell, Windows" /C:CDW and what you would see is shown below: MENU4 GKS 660 07-09-94 1:59a MENU5 GKS 1,725 07-09-94 1:59a FILELIST LST 445 07-09-94 3:29p GETKEY MAR 22,201 07-09-94 1:59a ENTERN SCR 9 07-09-94 1:59a WPLABEL SCR 11 07-09-94 1:59a DBLABEL SCR 14 07-09-94 1:59a GETKEY TXT 14,388 07-09-94 3:27p ÉÍÍÍÍÍÍÍÍÍÍ[ Select setup: Command line, DOS Shell, Windows ]ÍÍÍÍÍÍÍÍÍ» º º±± º Select setup: Command line, DOS Shell, Windows [C,D,W]? º±± C:º º±± º º±± C:º º±± º º±± C:ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk "Your choice" /n C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk "Select setup: Command line, DOS Shell, Windows" /c:cdw The /C switch tells GETKEY what keys for which to wait. In the case above, those would be C, D, and W, which are displayed as a prompt in GETKEY's output. Because the C key comes first, it will generate an errorlevel of 1, D will generate 2, and W will be 3. To test for these errorlevels in your batch files, you will need to stack your IF ERRORLEVEL statements carefully. The reason for this is because IF ERRORLEVEL tests out positive when the value returned is equal to or greater than the value specified in the IF ERRORLEVEL test. This can be tricky, as the following example shows: IF ERRORLEVEL 2 DOSSHELL Here, the DOSSHELL command is executed when an errorlevel of 2 or greater is returned. So, if the errorlevel is equal to 3 or 4 or 5, on up, the DOSSHELL command is executed. That's probably not what you want. To ensure that the proper errorlevel value is found, you can use the follow- ing batch-file statement: IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 command This statement executes the command when an errorlevel value of 1 is returned -- no more, no less. Perhaps the handiest feature of the GETKEY command is its timeout function. This lets your batch files proceed with automatic selections when the user is too pokey to type them. Here is an example using the timeout function: C:>GK /C:ABCD /T:C,60 "Your selection " And the output is below: ENTERN SCR 9 07-09-94 1:59a WPLABEL SCR 11 07-09-94 1:59a DBLABEL SCR 14 07-09-94 1:59a GETKEY TXT 14,388 07-09-94 3:27p 42 file(s) 325,958 bytes 55,623,680 bytes free C:\DOS\BATCH\1>gk ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ Your selection ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» C:º º±± º Your selection [A,B,C,D]? º±± C:º º±± º º±± C:º º±± º º±± C:ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk "Select setup: Command line, DOS Shell, Windows" /c:cdw C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk /c:abcd /t:c,60 "Your selection" If the user doesn't type anything for more than 60 seconds, the computer selects option C. GETKEY then generates an errorlevel value of 3, and the batch file continues. This works because of GETKEY's /T switch. The /T switch is followed by a colon, plus the key GETKEY will "press" 'c' automatically after 60 seconds of inactivity. This is really handy. By using GETKEY with its /T timeout in AUTOEXEC.BAT, you can have the computer start up without your input, for example after a powerup or if you reset but don't want to sit, watch, and provide information while the computer starts up. An interesting side effect of the /T switch is that you can use GETKEY to insert deliberate pauses into your batch files. For example, employing the command in this format: C:>GK /T:Y,60 /N With the following effect: 42 file(s) 325,958 bytes 55,623,680 bytes free C:\DOS\BATCH\1>gk C:\DOS\BATCH\1>edit getkey.txt C:\DOS\BATCH\1>gk "Your choice" C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk "Your choice" /n C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk "Select setup: Command line, DOS Shell, Windows" /c:cdw C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk /c:abcd /t:c,60 "Your selection" C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk /t:y,60 /n uses the /T switch to insert a 60-second pause into a batch file. You could use this line after a message display instead of the PAUSE command with its boring "Press any key" message. With GETKEY, the pause is brief, and the program continues "automatically." The /N switch suppresses the prompt and because no text was specified, you will have a blank line on the screen. To make your screen more colorful use GETKEY's /D switch. For example, to make a blue background with yellow foreground and white highlighted letters use the following format: C:>GK /D:1,14,15 "Your selection " Valid color values are shown in the table below. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» º Background ³ Foreground/Highlight º ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ º Black 0 ³ Black 0 º º Blue 1 ³ Blue 1 º º Green 2 ³ Green 2 º º Cyan 3 ³ Cyan 3 º º Red 4 ³ Red 4 º º Magenta 5 ³ Magenta 5 º º Brown 6 ³ Brown 6 º º Light Gray 7 ³ Light Gray 7 º º ³ Dark Gray 8 º º ³ Light Blue 9 º º ³ Light Green 10 º º ³ Light Cyan 11 º º ³ Light Red 12 º º ³ Light Magenta 13 º º ³ Yellow 14 º º ³ White 15 º º ³ Blink 128 º ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ Add 128 to foreground or highlight to create blink i.e. for blinking yellow highlight use /d,,142. NOTE: If you are using a monochrome monitor, the /d switch has no effect. The default colors are black,lightgray,white (/d:0,7,15). Now, you are probably asking, where do the highlighted letters come into play? That's the biggest part that MicroSoft(R) left out! Simply by using GETKEY's menu switch /M, you can have the key character you want the user to press for selecting the menu item. You can have as many /M switches as you have command line room for, and with DOS, remember that is 255. The syntax for the menu switch is: C:>GK /M"~Windows" /M"~DOS Shell" /M"~Command line" The '~' tells GETKEY the following character is to be a highlighted character, and a valid key choice. If you do not specify display colors with the /d switch, the default colors are black background,light gray foreground,white highlight. The output would appear as below: C:\DOS\BATCH\1>edit getkey.txt C:\DOS\BATCH\1>gk "Your choice" C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>gk "Your choice" /n ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» C:\DOS\BATCHº Command line DOS Shell Windows º±± º º±± C:\DOS\BATCHº º±±s" /c:cdw º º±± C:\DOS\BATCHº º±± º [C,D,W]? º±± C:\DOS\BATCHº º±± ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± C:\DOS\BATCH\1±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± C:\DOS\BATCH\1>gk /t:y,60 /n C:\DOS\BATCH\1>edit \sk\notes.txt C:\DOS\BATCH\1>GK /M"~Windows" /M"~DOS Shell" /M"~Command line" Because the program sorts the menu items before displaying them. Be sure to test your batch files without testing for ERRORLEVEL to see what order the menu will display. (Menu order affects the order of valid keys!) Also remember the tilde character falls after lower case letters in the ASCII character set, so if you use the following command: C:>GK /M"~Windows" /M"C~opy a file" /M"~Command line" this would be your output: C:\DOS\BATCH\1>gk "Select setup: Command line, DOS Shell, Windows" /c:cdw ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» C:\DOS\BATCHº Copy a file Command line Windows º±± º º±± C:\DOS\BATCHº º±± º º±± C:\DOS\BATCHº º±± º [O,C,W]? º±± C:\DOS\BATCHº º±± ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± C:\DOS\BATCH\1±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± not this: C:\DOS\BATCH\1>gk "Select setup: Command line, DOS Shell, Windows" /c:cdw ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» C:\DOS\BATCHº Windows Copy a file Command line º±± º º±± C:\DOS\BATCHº º±± º º±± C:\DOS\BATCHº º±± º [W,O,C]? º±± C:\DOS\BATCHº º±± ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± C:\DOS\BATCH\1±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± Also, you can have more than one valid key per menu item: C:>GK -m"~1. ~Windows" -m"~2. C~opy a file" -m"~3. ~Command line" ^ ^ ^ ^ ^ ^ 1 2 3 4 5 6 C:\DOS\BATCH\1>gk /c:abcd /t:c,60 "Your selection" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» C:\DOSº 1. Windows 2. Copy a file 3. Command line º±± º º±± C:\DOSº º±± º º±± C:\DOSº º±± º [1,W,2,O,3,C]? º±± C:\DOSº º±± ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± C:\DOS\B±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± just be sure to use: IF ERRORLEVEL 5 IF NOT ERRORLEVEL 7 GOTO COMLINE IF ERRORLEVEL 3 IF NOT ERRORLEVEL 5 GOTO COPFILE IF ERRORLEVEL 1 IF NOT ERRORLEVEL 3 GOTO WINDOZE and your batch file will go to the assigned label and continue processing. NOTE: Numbering your menu items is an easy way of ensuring the correct order of options. Because the program sorts the menu items before displaying them, test your batch file WITHOUT "IF ERRORLEVEL 1 IF NOT ERRORLEVEL 3 GOTO command" lines so you can see what order they will be displayed, also, be sure NOT to use the /n switch while testing, so you can see the order of the selection keys. The /f switch looks for the file named and reads the arguments listed. The file format is simple one argument per line. You cannot use the /f switch in the file. This is the contents of MENU.GKS found on this disk: /m"0~1. PC Tools" /m"0~2. Windows" /m"0~3. DOS Shell" /m"0~4. PC Shell" /m"0~5. CP Backup" /m"0~6. CPAV" /m"0~7. MS Backup" /m"0~8. MSAV" /m"0~9. BC++" /m"10. B~Pascal" /m"11. QB~asic" /m"12. Pain~t Brush" /m"13. W~inCim" /m"14. Pa~radox" /m"15. Q~uattro Pro" /m"16. ~dBase" /m"17. ~Jet Fighter" /m"18. Object ~Vision" /m"19. ~F-117" /m"20. ~Vette" /m"21. ~Baseball" /m"22. ~Mahjongg" /m"23. G~etkey" /m"24. ~Help!" /m"25. ~Run BBS" /m"26. ~Open door" /m"27. Page ~Sysop" /m"28. ~Good-bye!" /m"29. ~Quit" Here is how it is used with GETKEY: C:>GK /fmenu /s "Your choice" C:\DOS\BATCH\1>gk /c:abcd /t:c,60 "Your selection" ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ Menu ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» C:\DOº 01. PC Tools 11. QBasic 21. Baseball º±± º 02. Windows 12. Paint Brush 22. Mahjongg º±± C:\DOº 03. DOS Shell 13. WinCim 23. Getkey º±± º 04. PC Shell 14. Paradox 24. Help! º±± C:\DOº 05. CP Backup 15. Quattro Pro 25. Run BBS º±± º 06. CPAV 16. dBase 26. Open door º±± C:\DOº 07. MS Backup 17. Jet Fighter 27. Page Sysop º±± º 08. MSAV 18. Object Vision 28. Good-bye! º±± C:\DOº 09. BC++ 19. F-117 29. Quit º±± º 10. BPascal 20. Vette º±± C:\DOº º±± º º±± C:\DOº º±± º Your choice [1,2,3,4,5,6,7,8,9,P,a,t,i,r,u,d,J,V,F,V,B,M,e,H, º±± C:\DOº R,O,S,G,Q]? º±±line" ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± C:\DOS\±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± C:\DOS\BATCH\1>gk /fmenu /s "Your choice" Notice the use of /s to force case sensitivity. Without it 'r' or 'R' would select item #25 Run BBS. Also, notice the window is labeled with name of the .GKS file. You should use the full pathname for all .GKS files used in your batch file if you expect to use them anywhere other than the directory they are stored. When you use the full pathname it will be displayed as well as shown below: SCREEN BAT 1,854 07-09-94 1:59a SAMPLE BAT 2,142 07-09-94 6:33p MENU5 BAT 438 07-09-94 1:59a M25 COM 4,192 07-09-94 1:59a M50 ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ C:\dos\menu ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» GK º 01. PC Tools 11. QBasic 21. Baseball º±± GE º 02. Windows 12. Paint Brush 22. Mahjongg º±± COLORº 03. DOS Shell 13. WinCim 23. Getkey º±± CREATº 04. PC Shell 14. Paradox 24. Help! º±± MENU º 05. CP Backup 15. Quattro Pro 25. Run BBS º±± RUNMEº 06. CPAV 16. dBase 26. Open door º±± SCREEº 07. MS Backup 17. Jet Fighter 27. Page Sysop º±± D º 08. MSAV 18. Object Vision 28. Good-bye! º±± DIRSOº 09. BC++ 19. F-117 29. Quit º±± MENU5º 10. BPascal 20. Vette º±± FILELº º±± ENTERº º±± WPLABº º±± DBLABº º±± GETKEº º±± ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± C:\DOS\BATCH\1>gk /fc:\dos\menu /s /n If you strike an incorrect key a window will open informing you of your error and prompt you for any key. An example screen is shown below. SCREEN BAT 1,854 07-09-94 1:59a SAMPLE BAT 2,142 07-09-94 6:33p MENU5 BAT 438 07-09-94 1:59a M25 COM 4,192 07-09-94 1:59a M50 ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ[ C:\dos\menu ]ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» GK º 01. PC Tools 11. QBasic 21. Baseball º±± GE º 02. Windows 12. Paint Brush 22. Mahjongg º±± COLORº 03. DOS Shell 13. WinCim 23. Getkey º±± CREATº 04. PC Shell ÉÍÍÍÍÍÍÍÍÍÍÍ[ Error! ]ÍÍÍÍÍÍÍÍÍÍ» º±± MENU º 05. CP Backup º º±± º±± RUNMEº 06. CPAV º º±±r º±± SCREEº 07. MS Backup º º±±op º±± D º 08. MSAV º Invalid Response º±±! º±± DIRSOº 09. BC++ º º±± º±± MENU5º 10. BPascal º º±± º±± FILELº º º±± º±± ENTERº ÈÍ[ Press any key to continue ]ͼ±± º±± WPLABº ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± º±± DBLABº º±± GETKEº º±± ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±± ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± C:\DOS\BATCH\1>gk /fc:\dos\menu /s /n Because GETKEY is not the same as CHOICE any longer, this could be useful to everyone. If you have any ideas on how to improve it further please let me know via "The Penetentiary BBS", (706) 737-5631 (my brother runs that board so you can leave a private message with him or me. If you found this on a BBS in the Charleston area, you can leave a note for me where you found this. Also you can leave a message to me on CompuServe. My CompuServe address is shown above. Please let me know what you think of GETKEY this is the first program I have written to be used by anyone other than myself. Also, I am open to suggestions for improvements, add-ons, or what-have-you. There are fifteen batch files included with this ZIP file demonstrating how you could use GETKEY in your batch files. To run the batch files, make sure you are in the same drive and directory that they exist. If you plan on using any of these files on a regular basis, make sure the directory they exist in is included in your path statement, and edit the files that utilize the /m swich to include the full pathname, i.e. c:\dos\menu1.gks. Good luck and happy batch file programming. REGISTRATION FORM NAME: ___________________________________________ ADDRESS: _______________________________________ CITY: __________________________________________ STATE/PROVINCE: _________________________________ COUNTRY: _______________________________________ WHERE DID YOU GET GETKEY? __________________________________________________ ____________________________________________________________________________ WHAT WOULD YOU LIKE TO SEE ADDED/CHANGED? _________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ Send $10 (US) to: Matthew G. Moody 206 Waterwood Dr. Goose Creek, SC 29445-4838 Thank you for registering and supporting Shareware.